#ifndef STACK_H
#define STACK_H

#include <stdio.h>
template< typename T >
class Stack
{
    public:
        Stack( int size );
        ~Stack();
        bool isEmpty();
        bool isFull();
        bool push( T value );
        bool pop( T &value );
    private:
        int _size;
        int _top;
        T* _data;
};

template< typename T>
Stack<T>::Stack( int size )
{
    _size = ( size > 0 ? size : 10 );
    _data = new T[ _size ];
    _top = -1;
}

template< typename T>
Stack<T>::~Stack()
{
    delete [] _data;
}

template< typename T>
bool Stack<T>::isEmpty()
{
    return _top == -1;
}

template< typename T>
bool Stack<T>::isFull()
{
    return _top == _size - 1;
}

template< typename T>
bool Stack<T>::push( T value )
{
    if( isFull() )
        return false;

    _top++;
    _data[_top] = value;

    return true;
}

template< typename T>
bool Stack<T>::pop( T& value )
{
    if( isEmpty() )
        return false;

    value = _data[_top];
    _top--;

    return true;
}

#endif


